package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Equity;
import sanrenxing.dayEnd.backRepertoryTotal.domain.EquityTwo;

import java.util.List;

/**
 * 功能:权益处理数据层接口类
 * 编写者：
 * 日期：2021
 * 版本：1.0
 */
public interface EquityDao {
    /**
     * 分页查询条件
     * @param start
     * @param rows
     * @param condition
     * @return
     */
    @Select("select e.rightsId,f.seName,e.rigType,e.righDay,s.secNum,e.pro,decode(e.rigType,1,(s.secNum*e.pro*m.closePrice)/10,2,0) settMoney,decode(e.rigType,1,0,2,(s.secNum*e.pro)/10) bonusNum,e.proState from equityData e " +
            "join securitiesStock s on e.seId=s.seId join financialsecurities f on " +
            "e.seId=f.seId join marketData m on e.seId=m.seId where 1=1 ${condition} and to_char(e.righDay,'yyyy-MM-dd')>=to_char(sysdate,'yyyy-MM-dd') and to_char(e.righDay,'yyyy-MM-dd')=to_char(m.inputDate,'yyyy-MM-dd') and e.proState=-1")
    public List<EquityTwo> findByPage(@Param("start") int start, @Param("rows") int rows, @Param("condition") String condition);

    /**
     * 按条件统计记录数
     * @param condition 统计条件
     * @return 条件
     */
    @Select("select count(*) as counts from equityData e " +
            "join securitiesStock s on e.seId=s.seId join financialsecurities f on " +
            "e.seId=f.seId join marketData m on e.seId=m.seId where 1=1 ${condition}")
    public int count(@Param("condition") String condition);

    /**
     * 根据行情数据编号删除数据
     * @param rightsId 行情数据编号
     * @return 1：删除成功；0：删除失败
     */
    @Delete("delete from equityData where rightsId=#{rightsId}")
    public int delete(@Param("rightsId") int rightsId);

    /**
     * 修改权益处理数据
     * @param equity 权益处理数据对象
     * @return 1：修改成功；0：修改失败
     */
    @Update("update equityData set proState=#{proState} where rightsId=#{rightsId}")
    public int update(Equity equity);

    /**9
     * 查询所有权益处理数据
     * @return 权益处理数据对象集合
     */
    @Select("select e.rightsId,e.seId,e.rigType,e.righDay,s.secNum,s.caId,s.fundId,e.pro,decode(e.rigType,1,(s.secNum*e.pro*m.closePrice)/10,2,0) settMoney,decode(e.rigType,1,0,2,(s.secNum*e.pro)/10) bonusNum,e.proState from equityData e " +
            "join securitiesStock s on e.seId=s.seId join marketData m on e.seId=m.seId where to_char(e.righDay,'yyyy-MM-dd')=to_char(sysdate,'yyyy-MM-dd')  and to_char(e.righDay,'yyyy-MM-dd')=to_char(m.inputDate,'yyyy-MM-dd') and e.rightsId=#{rightsId}")
    public Equity findById(@Param("rightsId") int rightsId);
}
